import {
  getListPage
} from '@/api/comment.js'
import {
  CommentList
} from '@/layout/components'
export default {
  components: {
    CommentList
  },
  // filters: { // 字段转换
  //   statusFilter(status) {
  //     const statusMap = {
  //       published: 'success',
  //       draft: 'gray',
  //       deleted: 'danger'
  //     }
  //     return statusMap[status]
  //   }
  // },
  data() {
    return {
      empty_text: '暂无数据',
      listPages: {
        page: 1,
        size: 10,
        sizes: [5, 10, 15, 20, 30, 50, 100],
        total: 0
      },
      listParam: {
        page: 1,
        pageSize: 10
      },
      datas: [],
      listLoading: false,
      configCommentList: {
        visible: false
      },
      keys: {
        CommentList: new Date().getTime() + '' + Math.random()
      }
    }
  },
  created() {
    this._fetchData()
  },
  watch: {
    // $route: {
    //   handler() {
    //     this._fetchData()
    //   },
    //   deep: true // 深度监听，同时也可监听到param参数变化
    // },
    listPages: {
      handler() {
        this._fetchData()
      },
      deep: true // 深度监听，同时也可监听到param参数变化
    }
  },
  methods: {
    _fetchData() {
      this.listLoading = true
      this.listParam.page = this.listPages.page
      this.listParam.pageSize = this.listPages.size
      getListPage(this.listParam).then(response => {
        this.datas = response.result.list
        this.listPages.total = response.result.total
        this.listLoading = false
      })
    },
    _page_size_change(val) {
      // console.log(`每页 ${val} 条`)
      this.listPages.size = val
    },
    _page_prev_click() {
      this.listPages.page--
    },
    _page_current_change(val) {
      // console.log(`当前页: ${val}`)
      this.listPages.page = val
    },
    _page_next_click() {
      this.listPages.page++
    },
    detailRow(row) {
      // console.log(row)
      this.configCommentList.visible = true
      this.configCommentList.commodityId = row.commodityId
      this.keys.CommentList = new Date().getTime()
    },
    backCommentList(result) {
      this.configCommentList.visible = false
    }
  }
}
